package com.cg.controller;


import com.cg.dto.AddInheritorDTO;
import com.cg.dto.AddLikeDTO;
import com.cg.dto.AddNewsDTO;
import com.cg.dto.UpdateNewsDTO;
import com.cg.entity.News;
import com.cg.result.R;
import com.cg.service.INewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 加
 * @since 2025-01-17
 */
@RestController
@CrossOrigin
@RequestMapping("/api/news")
@Api(value = "newsController",description = "欢迎来到新闻管理",tags = "新闻管理")
public class NewsController {

    @Autowired
    private INewsService newsService;

    @ApiOperation("展示所有新闻")
    @GetMapping("/showNews")
    public R<List<News>> showNews(){
        return newsService.showNews();
    }

    @ApiOperation("新增收藏")
    @PostMapping("/addLike")
    public R addLike(AddLikeDTO addLikeDTO){
        return newsService.addLike(addLikeDTO);
    }

    @ApiOperation("新增新闻")
    @PostMapping("/addNews")
    public R addNews(@Validated @RequestBody AddNewsDTO addNewsDTO ){
        return newsService.addNews(addNewsDTO);
    }

    @ApiOperation("删除新闻")
    @DeleteMapping("/deleteNews")
    public R deleteNews(@RequestParam("newsId")Long newsId){
        return newsService.deleteNews(newsId);
    }

    @ApiOperation("修改新闻")
    @PutMapping("/updateNews")
    public R updateNews(@Validated @RequestBody UpdateNewsDTO updateNewsDTO){
        return newsService.updateNews(updateNewsDTO);
    }


}
